package evolution_superclasses;

import misc.not_Legal_Exception;

public abstract class Phenotype implements Comparable<Phenotype>{
	protected Genotype _genotype;
	private double _fitness;

	public Phenotype(Genotype gen){
		if(gen!=null){
			_genotype = gen;
			_fitness = 0;
			try {
				develop(gen);
			} catch (not_Legal_Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	public Phenotype(Genotype gen, boolean stallDevelop){
		if(gen!=null){
			_genotype = gen;
			_fitness = 0;
			if(stallDevelop)return;
			try {
				develop(gen);
			} catch (not_Legal_Exception e) {
				e.printStackTrace();
			}
		}
	}

	public Genotype get_genotype() {
		return _genotype;
	}

	public void set_genotype(Genotype genotype) {
		_genotype = genotype;
	}

	public double get_fitness() {
		return _fitness;
	}

	public void set_fitness(double fitness) {
		_fitness = fitness;
	}
	
	protected abstract void develop(Genotype gen) throws not_Legal_Exception;
	public abstract String toString();

	public int compareTo(Phenotype arg0) {
		double compareFitness = arg0.get_fitness(); 
		 
		//ascending order
		return (int)((compareFitness - get_fitness())*10000);
	}
}
